package exhibition.app.nexd.cn.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import exhibition.app.nexd.cn.R;
import exhibition.app.nexd.cn.model.OrderForm;

/**
 * 订单详细页面展示adapter
 * <p>
 * Created by xun on 2016/4/20.
 */
public class OrderFormAdapter extends BaseAdapter {
    private List<OrderForm> orderForms;
    private Context mContext;

    public OrderFormAdapter(List<OrderForm> orderForms, Context mContext) {
        this.orderForms = orderForms;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return orderForms.size();
    }

    @Override
    public OrderForm getItem(int position) {
        return orderForms.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_oderform_list, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        OrderForm orderForm = getItem(position);
        if (orderForm != null) {
            viewHolder.tvTitle.setText(orderForm.getTitle());
            viewHolder.tvPrice.setText(String.valueOf(orderForm.getPrice()));
            viewHolder.tvDays.setText(String.valueOf(orderForm.getDays() + "天"));
            viewHolder.tvNums.setText(String.valueOf(orderForm.getNum() + "件"));
        }
        return convertView;
    }

    static class ViewHolder {

        @Bind(R.id.order_form_tv_title)
        TextView tvTitle;
        @Bind(R.id.order_form_tv_price)
        TextView tvPrice;
        @Bind(R.id.order_form_tv_day)
        TextView tvDays;
        @Bind(R.id.order_form_tv_num)
        TextView tvNums;

        public ViewHolder(View convertView) {
            ButterKnife.bind(this, convertView);
        }
    }
}
